package fr.emn.integration.synthese.controle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.JOptionPane;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.abstraction.Evaluation;
import fr.emn.integration.synthese.presentation.EvaluationDialog;
import fr.emn.integration.synthese.presentation.NoteDialog;

public class ControlJButtonSaveNote implements ActionListener{
	
	private Cours modele;
	private boolean creation;
	private NoteDialog parent;
	
	public ControlJButtonSaveNote(Cours modele, boolean creation,
			NoteDialog parent) {
		super();
		this.modele = modele;
		this.creation = creation;
		this.parent = parent;
	}
	
	public void actionPerformed(ActionEvent e) {
		if (parent.getNote()<=20.0 && parent.getNote()>=0.0) {
			try {
				modele.saveNote(parent.getMailEleve(), parent.getNote());
				parent.setVisible(false);
			} catch (SQLException e1) {
				JOptionPane.showMessageDialog(parent, "On ne peut pas!", "Erreur!",
						JOptionPane.ERROR_MESSAGE);
				System.out.println(e1);
			}
		}
	}

}
